<%-- 
    Document   : newEvent
    Created on : May 12, 2011, 9:24:02 PM
    Author     : enriquer
--%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>

        <script src="/dojo-1.6.0/dojo/dojo.js" djConfig="parseOnLoad: true">
	
        </script>
        <script src="sevent.js"></script>
        <!--script src="pagination.js"></script-->
        <script type="text/javascript">
            dojo.require("dijit.layout.ContentPane");
            dojo.require("dijit.layout.BorderContainer");
            dojo.require("dijit.MenuBar");
            dojo.require("dijit.Menu");
            dojo.require("dijit.MenuBarItem");
            dojo.require("dijit.MenuItem");
            dojo.require("dijit.form.Button");
            dojo.require("dijit.form.Form");
            dojo.require("dijit.form.ValidationTextBox");
            dojo.require("dijit.form.SimpleTextarea");
            dojo.require("dijit.form.DateTextBox");
            dojo.require("dijit.form.CheckBox");
            dojo.require("dijit.TitlePane");
            dojo.require("dijit.layout.TabContainer");
            dojo.require("dijit.form.TimeTextBox");
            dojo.require("dijit.form.NumberSpinner");
            dojo.require("dojo.data.ItemFileReadStore");

            var totalItems = 0; //How many total items should we expect.
            var currentStart = 0; //Current index into the pages.
            var currentCount = 10; //Current size of the page.
            var request=null;
                
               
            //Callback for if the lookup fails.
            function fetchFailed(error, request) {
                alert("lookup failed.");
            }

            //Button event to page forward.
            function nextPage() {
                //If we haven't hit the end of the pages yet, allow for requesting another.
                if ((currentStart + currentCount) < totalItems) {
                    request.start += currentCount;
                    request = store.fetch(request);
                }
            }

            //Button event to page back;
            function previousPage() {
                //If we haven't hit the beginning of the pages yet, allow for another shift backwards.
                if (currentStart > 0) {
                    request.start -= currentCount;
                    request = store.fetch(request);
                }
            }
                
            dojo.addOnLoad(function() {
                
                 alert("amy");
                function clearOldList(size, request) {
                    var list = dojo.byId("listEvents");
                    if (list) {
                        while (list.firstChild) {
                            list.removeChild(list.firstChild);
                        }
                    }
                    //Save off the total size. We need it to determine when to ignore the buttons.
                    totalItems = size;
                }

                //Callback for processing a returned list of items.
                function gotItems(items, request) {
                    //Save off the current page info being displayed.
                    currentStart = request.start;
                    currentCount = request.count;
                    var list = dojo.byId("listEvents");
                    if (list) {
                        var i;
                        for (i = 0; i < items.length; i++) {
                            var item = items[i];
                            list.appendChild(document.createTextNode(store.getValue(item, "name")));
                            list.appendChild(document.createElement("br"));
                        }
                    }
                }
            
                request = store.fetch({
                    onBegin: clearOldList,
                    onComplete: gotItems,
                    onError: fetchFailed,
                    start: currentStart,
                    count: currentCount
                });
              
            });
        </script>

        <link rel="stylesheet" type="text/css"
              href="/dojo-1.6.0/dijit/themes/claro/claro.css" />
        <style type="text/css">
            body,html {
                font-family: helvetica, arial, sans-serif;
                font-size: 90%;
                width: 90%;
                height: 100%;
                margin: 0;
                overflow: auto;
                margin-left: auto;
                margin-right: auto;
            }

            #divMainContainer {
                width: 100%;
                height: 100%;
            }
            #centered
        </style>

    </head>


    <body class="claro">

        <div dojoType="dojo.data.ItemFileReadStore" jsId="store" url="lsEvents.htm" 
             urlPreventCache="true" clearOnClose="true">
        </div>

        <div dojoType="dijit.layout.TabContainer" style="width: 100%; height: 100%;">
            <div dojoType="dijit.layout.ContentPane" title="<spring:message code='newevent.editevent'/>" selected="true">
                <div id="divMessage" align="center"></div>

                <div dojoType="dijit.form.Button" jsId="back" onclick="javascript:previousPage();">
                    Click me for the previous page!
                </div>
                <div dojoType="dijit.form.Button" jsId="forward" onclick="javascript:nextPage();">
                    Click me for the next page!
                </div>
                <br>
                <span id="listEvents">
                </span>

            </div>

        </div>

    </body>
</html>


